Skip to main content

Link Options

gpAddLinkOption() adds linker flags to a target. Like the other GPBT APIs, GPBT already applies the correct per-linker and per-configuration flags automatically — use this one for module-specific linker requirements.

Syntax

gpAddLinkOption(visibility flag [flag2 ...])

visibility is one of PUBLIC, PRIVATE, or INTERNAL.

Common use cases

Version scripts and symbol visibility

On Linux, you can restrict which symbols a shared library exports:

gpStartModule("renderer/core")
if(UNIX AND NOT APPLE)
gpAddLinkOption(PRIVATE "-Wl,--version-script=${CMAKE_CURRENT_LIST_DIR}/renderer_core.map")
endif()
gpEndModule()

Subsystem selection on Windows

gpStartExecutable("launcher")
if(WIN32)
gpAddLinkOption(PRIVATE /SUBSYSTEM:WINDOWS)
endif()
gpEndExecutable()
tip

For GUI executables on Windows, prefer gpSetGuiExecutable() rather than adding /SUBSYSTEM:WINDOWS manually. See Executable Specific for details.

System library flags

gpStartModule("platform")
if(UNIX AND NOT APPLE)
gpAddLinkOption(PRIVATE -ldl -lpthread)
endif()
gpEndModule()

Generator expressions work the same way as for compile options:

gpStartModule("core")
gpAddLinkOption(PRIVATE "$<$<CONFIG:Shipping>:-Wl,--gc-sections>")
gpEndModule()

Visibility reference

VisibilityEffect
PUBLICApplied to this target and propagated to all dependents
PRIVATEApplied to this target only
INTERNALApplied to this target and modules connected via INTERNAL dependency edges